﻿using DVM.DB.Model;
using DVM.DV;
using DVM.DV.Extensions;
using DVM.DV.Model;
using DVM.VM;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace DVM.DB.DataQuery
{
    [PropertySet(DBField.ProductTypeId)]
    public class ProductTypeQuery : DVContext<int, string>
    {

        public ProductTypeQuery(InitInfo initInfo) :
            base(initInfo)
        {

        }

        /// <summary>
        /// ViewModel数据查询
        /// </summary>
        /// <returns></returns>
        public override Dictionary<int, string> ConvertView()
        {
            var keys = GetPropertyValue();
            var dbQuery = QueryProductTypeFromDB(keys);
            return dbQuery.Distinct().ToDictionary(x => x.Id, x => x.ProductTypeName);
        }

        /// <summary>
        /// 数据查询
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static List<ProductType> QueryProductTypeFromDB(List<int> keys)
        {
            return DBData.GetProductTypeQuery().Where(x => keys.Contains(x.Id)).ToList();
        }
    }
}
